In [12]:
import tensorflow as tf

Hello, Tensor World!


In [13]:
# Create TensorFlow object called tensor
hello_constant = tf.constant('Hello World!')

In [14]:
with tf.Session() as sess:
    # Run the tf.constant operation in the session
    output = sess.run(hello_constant)
    print(output)


b'Hello World!'

In [15]:
# A is a 0-dimensional int32 tensor
A = tf.constant(1234)

In [16]:
with tf.Session() as sess:
    # Run the tf.constant operation in the session
    output = sess.run(A)
    print(output)


1234

In [17]:
# B is a 1 dimentional int32 tensor
B = tf.constant([123,456,789])

In [18]:
with tf.Session() as sess:
    # Run the tf.constant operation in the session
    output = sess.run(B)
    print(output)


[123 456 789]

In [19]:
# C is a 2-dimensional int32 tensor
C = tf.constant([[123,456,789],[222,333,444]])

In [20]:
with tf.Session() as sess:
    # Run the tf.constant operation in the session
    output = sess.run(C)
    print(output)


[[123 456 789]
 [222 333 444]]

In [21]:
with tf.Session() as sess:
    print(sess.run(hello_constant))
    print(sess.run(A))
    print(sess.run(B))
    print(sess.run(C))


b'Hello World!'
1234
[123 456 789]
[[123 456 789]
 [222 333 444]]

TensorFlow Input


In [27]:
x = tf.placeholder(tf.string)

with tf.Session() as sess:
    output = sess.run(x, feed_dict={x: 'Hello World'})
    print(output)


Hello World

In [40]:
x = tf.placeholder(tf.string)
y = tf.placeholder(tf.int32)
z = tf.placeholder(tf.float32)

with tf.Session() as sess:
    output = sess.run(z, feed_dict={x: 'Test String', y: 123, z: 45.67})
    print(output)
    print(x)
    print(y)
    print(z)


45.66999816894531
Tensor("Placeholder_42:0", dtype=string)
Tensor("Placeholder_43:0", dtype=int32)
Tensor("Placeholder_44:0", dtype=float32)

Quiz 1 - TensorFlow Input


In [53]:
def run():
    output = None
    x = tf.placeholder(tf.int32)
    
    with tf.Session() as sess:
        output = sess.run(x, feed_dict={x: 123})
        print(output)
        
    return output

In [54]:
output = None
x1 = tf.placeholder(tf.int32)

with tf.Session() as sess:
    output = sess.run(x1, feed_dict={x1: 123})
    print(output)


123